package app.scene;

import puri01.ValueList;
import puri01.game.GameControlGroup;
import app.game.common.Background;
import app.game.common.Global;
import app.game.common.Ship;
import app.game.level.GameLevel;
import app.game.level.GameLevel01;
import app.game.level.GameLevel02;
import app.game.level.GameLevel03;
import app.scene.Scene;

public class SceneGame extends Scene {

	private static SceneGame _MyObject = null;

	public SceneGame(GameControlGroup gameControlGroup) {
		super(gameControlGroup);
		
		_MyObject = this;
		
		gameControlGroup.addControl(this);
	}
	
	public static SceneGame getInstance() {
	    return _MyObject;
	}
	
	private Background _Background = null;
	private Ship _Ship = null;
	
	private GameLevel _GameLevel = null;
	
	public void setGameLevel(int level) {
		Global.gameInformation.setGameLevel(level);

		if (_GameLevel != null) {
			_GameLevel.actionOut();
			_GameLevel = null;
		}
		
		switch (level) {
			case 1: _GameLevel = new GameLevel01(getGameControlGroup()); break;
			case 2: _GameLevel = new GameLevel02(getGameControlGroup()); break;
			case 3: _GameLevel = new GameLevel03(getGameControlGroup()); break;
			default: ; // TODO : raise Exception
		}
		
		getGameControlGroup().addControl(_GameLevel);
		
		_GameLevel.actionIn();
	}
	
	@Override
	public void actionIn(Scene oldScene, ValueList params) {
		Global.gameInformation.startGame();
		
		_Background = new Background(getGameControlGroup());
		_Ship = new Ship(getGameControlGroup());

		getGameControlGroup().addControl(_Background);
		getGameControlGroup().addControl(_Ship);
		getGameControlGroup().addControl(Global.gameInformation);
		
		setGameLevel(1);
	}

	@Override
	public void actionOut(Scene newScene) {
		if (_GameLevel != null) {
			_GameLevel.actionOut();
			_GameLevel = null;
		}
		
		Global.gameInformation.delete();
		_Ship.delete();
		_Background.delete();

		_Ship = null;
		_Background = null;
	}
	
}
